package com.ys.servers.test;

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.json.JsonObject;


/**
 * Created by taotao on 2017/2/24.
 */
public class VerticleStarter {

    private Vertx vertx;

    public VerticleStarter() {
        vertx = Vertx.vertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE));
    }

    public static void main(String args[]) {

        VerticleStarter tester = new VerticleStarter();
        tester.testDeployApiGateWay();
        //tester.testDeployPointsVerticle();
        tester.testDeployVersionsVerticle();
        tester.testDeployPointsVerticle();
        //tester.testDeployUserVerticle();
        //tester.testDeployAdminVerticle();
    }

    public void testDeployApiGateWay() {
        String myConfig = "{\n" +
                "  \"service.name\": \"api-gateway\",\n" +
                "  \"api.gateway.http.address\": \"0.0.0.0\",\n" +
                "  \"api.gateway.http.port\": 18886,\n" +
                "  \"mongo.host\": \"121.41.117.201\",\n" +
                "  \"mongo.port\": 27017,\n" +
                "  \"data.space\": \"YsServer\",\n" +
                "  \"redis.host\": \"114.55.251.115\",\n" +
                "  \"redis.port\": 63557,\n" +
                "  \"redis.db\": 5,\n" +
                "  \"verticles\": [\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.gateway.verticle.RestfulGateWayVerticle\"\n" +
                "    },\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.gateway.verticle.WebSocketGateWayVerticle\"\n" +
                "    }\n" +
                "  ]\n" +
                "}";

        JsonObject obj = new JsonObject(myConfig);//.getJsonObject(myConfig);
        /*vertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE).setClustered(true).setClustered(true), as -> {

            System.out.println("Start to deploy YS Servers Verticle Cluster . . . . . .  ");

            Vertx vertx = as.result();*/
        vertx.deployVerticle("com.ys.servers.common.verticle.DeployVerticle",
                new DeploymentOptions().setConfig(obj), res -> {

                });
        // });

    }

    public void testDeployPointsVerticle() {

        String myConfig = "{\n" +
                "  \"service.name\": \"points-service\",\n" +
                "  \"api.name\":\"points\",\n" +
                "  \"points.rest.http.address\": \"0.0.0.0\",\n" +
                "  \"points.rest.http.port\": 18888,\n" +
                "  \"mongo.host\": \"121.41.117.201\",\n" +
                "  \"mongo.port\": 27017,\n" +
                "  \"name.space\": \"YsServer\",\n" +
                "  \"redis.host\": \"114.55.251.115\",\n" +
                "  \"redis.port\": 63557,\n" +
                "  \"redis.db\": 5,\n" +
                "  \"verticles\": [\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.points.verticle.PointsVerticle\"\n" +
                "    }\n" +
                "  ]\n" +
                "}";


        JsonObject obj = new JsonObject(myConfig);//.getJsonObject(myConfig);
       /* Vertx.clusteredVertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE).setClustered(true).setClustered(true), as -> {

            System.out.println("Start to deploy YS Servers Verticle Cluster . . . . . .  ");

            Vertx vertx = as.result();*/
        vertx.deployVerticle("com.ys.servers.common.verticle.DeployVerticle",
                new DeploymentOptions().setConfig(obj), res -> {

                });
//        });

    }

    public void testDeployVersionsVerticle() {

        String myConfig = "{\n" +
                "  \"service.name\": \"versions-service\",\n" +
                "  \"api.name\":\"versions\",\n" +
                "  \"points.rest.http.address\": \"0.0.0.0\",\n" +
                "  \"points.rest.http.port\": 18889,\n" +
                "  \"mongo.host\": \"121.41.117.201\",\n" +
                "  \"mongo.port\": 27017,\n" +
                "  \"name.space\": \"YsServer\",\n" +
                "  \"redis.host\": \"114.55.251.115\",\n" +
                "  \"redis.port\": 63557,\n" +
                "  \"redis.db\": 5,\n" +
                "  \"verticles\": [\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.versions.verticle.VersionsVerticle\"\n" +
                "    }\n" +
                "  ]\n" +
                "}";


        JsonObject obj = new JsonObject(myConfig);//.getJsonObject(myConfig);
      /*  Vertx.clusteredVertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE).setClustered(true).setClustered(true), as -> {

            System.out.println("Start to deploy Ys-Versions Servers Verticle Cluster . . . . . .  ");

            Vertx vertx = as.result();*/
        vertx.deployVerticle("com.ys.servers.common.verticle.DeployVerticle",
                new DeploymentOptions().setConfig(obj), res -> {

                });
        //  });

    }

    public void testDeployUserVerticle() {

        String myConfig = "{\n" +
                "  \"service.name\": \"user-service\",\n" +
                "  \"api.name\":\"user\",\n" +
                "  \"user.rest.http.address\": \"0.0.0.0\",\n" +
                "  \"user.rest.http.port\": 18890,\n" +
                "  \"mongo.host\": \"121.41.117.201\",\n" +
                "  \"mongo.port\": 27017,\n" +
                "  \"name.space\": \"YsServer\",\n" +
                "  \"redis.host\": \"114.55.251.115\",\n" +
                "  \"redis.port\": 63557,\n" +
                "  \"redis.db\": 5,\n" +
                "  \"verticles\": [\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.user.verticle.UserVerticle\"\n" +
                "    }\n" +
                "  ]\n" +
                "}";


        JsonObject obj = new JsonObject(myConfig);//.getJsonObject(myConfig);
      /*  Vertx.clusteredVertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE).setClustered(true).setClustered(true), as -> {

            System.out.println("Start to deploy Ys-Versions Servers Verticle Cluster . . . . . .  ");

            Vertx vertx = as.result();*/
        vertx.deployVerticle("com.ys.servers.common.verticle.DeployVerticle",
                new DeploymentOptions().setConfig(obj), res -> {
                    if(res.succeeded()){

                    }else{
                        int i=0;
                    }
                });
        //  });

    }

    public void testDeployAdminVerticle() {

        String myConfig = "{\n" +
                "  \"service.name\": \"admin-service\",\n" +
                "  \"api.name\":\"admin\",\n" +
                "  \"admin.key\":\"ho1HMiyaerqQL4ySn\",\n" +
                "  \"points.rest.http.address\": \"0.0.0.0\",\n" +
                "  \"points.rest.http.port\": 18891,\n" +
                "  \"mongo.host\": \"121.41.117.201\",\n" +
                "  \"mongo.port\": 27017,\n" +
                "  \"name.space\": \"YsServer\",\n" +
                "  \"redis.host\": \"121.41.117.201\",\n" +
                "  \"redis.port\": 6379,\n" +
                "  \"redis.db\": 5,\n" +
                "  \"verticles\": [\n" +
                "    {\n" +
                "      \"name\": \"com.ys.servers.admin.verticle.AdminVerticle\"\n" +
                "    }\n" +
                "  ]\n" +
                "}";


        JsonObject obj = new JsonObject(myConfig);//.getJsonObject(myConfig);
      /*  Vertx.clusteredVertx(new VertxOptions().setMaxEventLoopExecuteTime(Long.MAX_VALUE)
                .setMaxWorkerExecuteTime(Long.MAX_VALUE).setClustered(true).setClustered(true), as -> {

            System.out.println("Start to deploy Ys-Versions Servers Verticle Cluster . . . . . .  ");

            Vertx vertx = as.result();*/
        vertx.deployVerticle("com.ys.servers.common.verticle.DeployVerticle",
                new DeploymentOptions().setConfig(obj), res -> {
                    if(res.succeeded()){

                    }else{
                        int i=0;
                    }
                });
        //  });

    }
}
